﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace AirWar
{
    public class Bullet
    {
        #region 私有字段
        //子弹的所属方
        Side _side;
        //子弹的坐标位置
        private Point _position;
        //子弹的发射方向
        private Direction _direction;
        //子弹的步长
        private int _step;
        //子弹的尺寸大小
        private Size _size;
        //子弹是否有效
        private bool _enable = true;
        //子弹图片
        private Bitmap _bulletBmp;
        #endregion
        #region 公有属性
        public Side _Side { get => _side; set => _side = value; }
        public Point _Position { get => _position; set => _position = value; }
        public Direction _Direction { get => _direction; set => _direction = value; }
        public int _Step { get => _step; set => _step = value; }
        public Size _Size { get => _size; set => _size = value; }
        public bool _Enable { get => _enable; set => _enable = value; }
        #endregion
        //构造方法
        public Bullet(Side side)
        {
            //设置子弹的所属方
            _side = side;
            //根据子弹的所属方,装载相应的子弹图片,并设置子弹的步长
            if(side == Side.Me)
            {
                _bulletBmp = new Bitmap("image\\myBullet.png");
                _direction = Direction.Down;
                _step = 20;
            }
            else
            {
                _bulletBmp = new Bitmap("image\\enemyBullet.png");
                _direction = Direction.Up;
                _step = 15;
            }
            //设置子弹图片的透明色
            _bulletBmp.MakeTransparent(Color.Black);
            //设置子弹的尺寸大小
            _size = new Size(_bulletBmp.Width, _bulletBmp.Height);
        }
        //子弹绘制
        public void DrawMe(Graphics g)
        {
            //绘制子弹图片
            g.DrawImage(_bulletBmp, _position);
        }
        //子弹移动
        public void Move()
        {
            //如果是我方子弹,则向上移动
            if (_side == Side.Me)
                _position.Y = _position.Y - _step;
            //如果是敌方子弹,则向下移动
            else
                _position.Y = _position.Y + _step;
        }
      
    }
}
